.NET Framework Class Library |
ParallelEnumerable..::.FirstOrDefault<(Of <(TSource>)>) Method (ParallelQuery<(Of <(TSource>)>), Func<(Of <(TSource, Boolean>)>)) |
ParallelEnumerable Class See Also Send Feedback |
Returns the first element of the parallel sequence that satisfies a condition or a
default value if no such element is found.
Namespace:
System.Linq
Assembly:
System.Threading (in System.Threading.dll)
Syntax
Visual Basic (Declaration) |
---|
Public Shared Function FirstOrDefault(Of TSource) ( _ source As ParallelQuery(Of TSource), _ predicate As Func(Of TSource, Boolean) _ ) As TSource |
C# |
---|
public static TSource FirstOrDefault<TSource>( ParallelQuery<TSource> source, Func<TSource, bool> predicate ) |
Parameters
- source
- Type: System.Linq..::.ParallelQuery<(Of <(TSource>)>)
The sequence to return an element from.
- predicate
- Type: System..::.Func<(Of <(TSource, Boolean>)>)
A function to test each element for a condition.
Type Parameters
- TSource
- The type of the elements of source.
Return Value
default(TSource) if source is empty or if no element passes the test specified by predicate; otherwise, the first element in source that passes the test specified by predicate.Remarks
There's a temporary difference from LINQ to Objects, this does not throw
ArgumentNullException when the predicate is null.
Exceptions
Exception | Condition |
---|---|
System..::.ArgumentNullException | source or predicate is a null reference (Nothing in Visual Basic). |
System..::.AggregateException | One or more exceptions occurred during the evaluation of the query. |
System..::.OperationCanceledException | The query was canceled. |